java如何解决这个索引器?
我的问题是,我需要将此Java代码更改为python:
public static byte x1=0,x2=0,x3=0,x4=0,x5=0,x6=0;
这是python的Java代码
jammon对我说,我只能把所有这些放在这行:
x = [0]*6
但现在当我运行代码时,我看到:
Traceback (most recent call last):
File "test.py", line 62, in <module> # The line 62 is the location of x[0]=datosOEM[k];
x[0]=datosOEM[k];
IndexError:bytearray index out of range
我已经看了其他帖子,但我还没有得到它。这是代码的一部分:
# -*- coding: utf-8 -*-
import serial
datosOEM=bytearray(5)
print(datosOEM)
datosOEM[0]=65
print(datosOEM)
x=[0]*6
k=0;
trama=1;
B=0;
C=0;
conexion=True;
resp=0
if(conexion):
#{
print ('conexion ON')
while(resp<200):
print ('data save')
while(C==0):
#{
print ('what is C?')
x[0]=datosOEM[k];
if(x[0]==1):
#{
print ('what is x[0]?')
x[1]=datosOEM[k+1];
if((x[1]&1)==1):
#{
print ('what is x[1]?')
C=1;
#}
#}
k=k+1;
#}
k=k-1;
...
明确地说,我的问题是:如何在python中创建一些不超出范围的ByteArray强>
我感谢你在这方面给予我的一切支持
请不要对我太苛刻我只是在学习
# 1 楼答案
为了解决这个问题,我做了一点改变
到
这样我就可以解决这个问题